Function.prototype.then = function(fullied, failed) {
    // 保存前一个promise的this
    const self = this
    return new Mypromise((resolve, reject) => {
        // 封装前一个promise成功时执行的函数
        let success  = () => {
            try {
                const result = fullied(self.value)
                return result instanceof Mypromise ? result.then(resolve, reject) : resolve(result)
            }
            catch(err) {
                throw err
            }
        }
        let rejected = () => {
            try {
                const result = failed(self.reson)
                return result instanceof Mypromise ? result.then(resolve, reject) : reject(result)
            }
            catch(err) {
                throw err
            }
        }
        switch(self.state) {
            case pending:
                self.fulliedCallback.push(fullied)
                self.failedCallback.push(failed)
                break
            case fullied:
                success()
                break
            case failed:
                rejected()
                break
        }
    })
}